package com.edu.producerAndConsumer;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Scanner;

@Data
@AllArgsConstructor
public class Consumer {
    private final Clerk clerk;

    public void buy() {
        while (true) {
            Scanner scanner = new Scanner(System.in);
            int buyNum = scanner.nextInt();
            synchronized (clerk) {
                if (clerk.getProduction() >= buyNum) {
                    clerk.setProduction(clerk.getProduction() - buyNum);
                    System.out.println(Thread.currentThread().getName() + " -- 消费ing... 产品余量为" + clerk.getProduction());
                    clerk.notify();
                }
            }
        }
    }
}
